<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$uniacid=$_SESSION['uniacid'];
model('jy_weishop/member')->checklogin();
$mid=$_SESSION['uid'];
if($_RQ['op']=='main'){
	$orderid=intval($_RQ['id']);
	$selfnumber=$_RQ['selfnumber'];
	if (empty($selfnumber)) {
			exi('请输入预约码!','error','jy_shopbaoxiu/index/');
	}
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$order_verify=$this->pdo_get('order',array('uniacid'=>$uniacid,'selfnumber'=>$selfnumber));
	if (empty($order_verify)) 
	{
		exi('预约码错误,无权核销','error','jy_shopbaoxiu/index/');   
	}
	//核销店员身份
	$prams=array('status'=>1,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']);
	$saler=pdo_get('jy_shouhou_member',$prams);
	if(empty($saler)){
		exi('您不是师傅','error','jy_shopbaoxiu/index/');   
	}
	if($order['status']==0 || $order['status']==3){
		exi('订单未付款或已关闭!','error','jy_shopbaoxiu/index/');
	}
	if($order['status']==3){
		exi('订单已关闭，不能核销！','error','jy_shopbaoxiu/index/');
	}elseif($order['status']==5){
		exi('订单已申请退款，不能核销！','error','jy_shopbaoxiu/index/');
	}elseif($order['status']==5){
		exi('订单已退款，不能核销！','error','jy_shopbaoxiu/index/');
	}
	if ($order_verify['status'] ==4) {	
		exi('该预约码已被使用!','error','jy_shopbaoxiu/index/');		
	}
	$return['post']=array(
		'orderid'=>$order_verify['id'],
		'verify_code'=>$selfnumber,
	);
	$return['order']=$order_verify;
	set_html('title','核销');
    exi($return);
}

if($_RQ['op']=='post'){
	$post=get_postdata();
	$orderid=intval($post['orderid']);
	$verify_code=trim($post['verify_code']);
	$this->model('verify')->self_verify($verify_code,$_SESSION['uid']);
	exi('核销成功！','','jy_shopbaoxiu/index/');
	
}